#include "DcdcData.h"

#include <float.h>
#include <limits.h>

#include "ComDefine.h"

bool CDcdcData::IsCommNormal()
{
    return (0 == m_uCommState);
}

bool CDcdcData::IsCommFault()
{
    return (1 == m_uCommState);
}

//获取***的显示文本
QString CDcdcData::GetCommStateText()
{
    if (0xFFFF == m_uCommState)
    {
        return QObject::tr("---");
    }
    else if (1 == m_uCommState)
    {
        return QObject::tr("故障");
    }
    else
    {
        return QObject::tr("正常");
    }
}

void CDcdcData::InitToInvalid()
{
    m_uCommState = 0xFFFF;
    for (int i = 0; i < ARRAYSIZE(m_uRev); ++i)
    {
        m_uRev[i] = 0xFFFF;
    }
    for (int i = 0; i < ARRAYSIZE(m_fRev); ++i)
    {
        m_fRev[i] = FLT_MAX;
    }

    //转发的100个UINT16数据
    m_uRunState = 0xFFFF;
    m_uFaultState = 0xFFFF;
    m_uAlarmState = 0xFFFF;
    m_uSwitchState = 0xFFFF;

    m_uDcWord1 = 0xFFFF;
    m_uDcState1 = 0xFFFF;
    m_uDcFault1 = 0xFFFF;
    m_uDcAlarm1 = 0xFFFF;

    m_uDcWord2 = 0xFFFF;
    m_uDcState2 = 0xFFFF;
    m_uDcFault2 = 0xFFFF;
    m_uDcAlarm2 = 0xFFFF;

    m_uDcWord3 = 0xFFFF;
    m_uDcState3 = 0xFFFF;
    m_uDcFault3 = 0xFFFF;
    m_uDcAlarm3 = 0xFFFF;

    m_uDcWord4 = 0xFFFF;
    m_uDcState4 = 0xFFFF;
    m_uDcFault4 = 0xFFFF;
    m_uDcAlarm4 = 0xFFFF;

    m_uDcWord5 = 0xFFFF;
    m_uDcState5 = 0xFFFF;
    m_uDcFault5 = 0xFFFF;
    m_uDcAlarm5 = 0xFFFF;

    m_uDcWord6 = 0xFFFF;
    m_uDcState6 = 0xFFFF;
    m_uDcFault6 = 0xFFFF;
    m_uDcAlarm6 = 0xFFFF;

    for (int i = 0; i < ARRAYSIZE(m_uData); ++i)
    {
        m_uData[i] = 0xFFFF;
    }

    //转发的100个FLOAT数据
    m_fTotalEnergy = FLT_MAX;
    m_fHighVol = FLT_MAX;
    m_fHighCur = FLT_MAX;
    m_fHighActPower = FLT_MAX;
    m_fInwindTemp = FLT_MAX;
    m_fOutwindTemp = FLT_MAX;

    m_fLowVol1 = FLT_MAX;
    m_fLowCur1 = FLT_MAX;
    m_fLowActPower1 = FLT_MAX;

    m_fLowVol2 = FLT_MAX;
    m_fLowCur2 = FLT_MAX;
    m_fLowActPower2 = FLT_MAX;

    m_fLowVol3 = FLT_MAX;
    m_fLowCur3 = FLT_MAX;
    m_fLowActPower3 = FLT_MAX;

    m_fLowVol4 = FLT_MAX;
    m_fLowCur4 = FLT_MAX;
    m_fLowActPower4 = FLT_MAX;

    m_fLowVol5 = FLT_MAX;
    m_fLowCur5 = FLT_MAX;
    m_fLowActPower5 = FLT_MAX;

    m_fLowVol6 = FLT_MAX;
    m_fLowCur6 = FLT_MAX;
    m_fLowActPower6 = FLT_MAX;

    for (int i = 0; i < ARRAYSIZE(m_fData); ++i)
    {
        m_fData[i] = FLT_MAX;
    }

    for (int i = 0; i < ARRAYSIZE(m_uSetData); ++i)
    {
        m_uSetData[i] = 0xFFFF;
    }

    for (int i = 0; i < ARRAYSIZE(m_uSetDataCopy); ++i)
    {
        m_uSetDataCopy[i] = 0xFFFF;
    }
}

void CDcdcData::InitToZero()
{
    m_uCommState = 0;
    for (int i = 0; i < ARRAYSIZE(m_uRev); ++i)
    {
        m_uRev[i] = 0;
    }
    for (int i = 0; i < ARRAYSIZE(m_fRev); ++i)
    {
        m_fRev[i] = 0.0;
    }

    //转发的100个UINT16数据
    m_uRunState = 0;
    m_uFaultState = 0;
    m_uAlarmState = 0;
    m_uSwitchState = 0;

    m_uDcWord1 = 0;
    m_uDcState1 = 0;
    m_uDcFault1 = 0;
    m_uDcAlarm1 = 0;

    m_uDcWord2 = 0;
    m_uDcState2 = 0;
    m_uDcFault2 = 0;
    m_uDcAlarm2 = 0;

    m_uDcWord3 = 0;
    m_uDcState3 = 0;
    m_uDcFault3 = 0;
    m_uDcAlarm3 = 0;

    m_uDcWord4 = 0;
    m_uDcState4 = 0;
    m_uDcFault4 = 0;
    m_uDcAlarm4 = 0;

    m_uDcWord5 = 0;
    m_uDcState5 = 0;
    m_uDcFault5 = 0;
    m_uDcAlarm5 = 0;

    m_uDcWord6 = 0;
    m_uDcState6 = 0;
    m_uDcFault6 = 0;
    m_uDcAlarm6 = 0;

    for (int i = 0; i < ARRAYSIZE(m_uData); ++i)
    {
        m_uData[i] = 0;
    }

    //转发的100个FLOAT数据
    m_fTotalEnergy = 0.0;
    m_fHighVol = 0.0;
    m_fHighCur = 0.0;
    m_fHighActPower = 0.0;
    m_fInwindTemp = 0.0;
    m_fOutwindTemp = 0.0;

    m_fLowVol1 = 0.0;
    m_fLowCur1 = 0.0;
    m_fLowActPower1 = 0.0;

    m_fLowVol2 = 0.0;
    m_fLowCur2 = 0.0;
    m_fLowActPower2 = 0.0;

    m_fLowVol3 = 0.0;
    m_fLowCur3 = 0.0;
    m_fLowActPower3 = 0.0;

    m_fLowVol4 = 0.0;
    m_fLowCur4 = 0.0;
    m_fLowActPower4 = 0.0;

    m_fLowVol5 = 0.0;
    m_fLowCur5 = 0.0;
    m_fLowActPower5 = 0.0;

    m_fLowVol6 = 0.0;
    m_fLowCur6 = 0.0;
    m_fLowActPower6 = 0.0;

    for (int i = 0; i < ARRAYSIZE(m_fData); ++i)
    {
        m_fData[i] = 0.0;
    }

    for (int i = 0; i < ARRAYSIZE(m_uSetData); ++i)
    {
        m_uSetData[i] = 0;
    }

    for (int i = 0; i < ARRAYSIZE(m_uSetDataCopy); ++i)
    {
        m_uSetDataCopy[i] = 0;
    }
}

void CDcdcData::InitToValue(quint16 uvalue, float fvalue)
{
    m_uCommState = uvalue;
    for (int i = 0; i < ARRAYSIZE(m_uRev); ++i)
    {
        m_uRev[i] = uvalue;
    }
    for (int i = 0; i < ARRAYSIZE(m_fRev); ++i)
    {
        m_fRev[i] = fvalue;
    }

    //转发的100个UINT16数据
    m_uRunState = uvalue;
    m_uFaultState = uvalue;
    m_uAlarmState = uvalue;
    m_uSwitchState = uvalue;

    m_uDcWord1 = uvalue;
    m_uDcState1 = uvalue;
    m_uDcFault1 = uvalue;
    m_uDcAlarm1 = uvalue;

    m_uDcWord2 = uvalue;
    m_uDcState2 = uvalue;
    m_uDcFault2 = uvalue;
    m_uDcAlarm2 = uvalue;

    m_uDcWord3 = uvalue;
    m_uDcState3 = uvalue;
    m_uDcFault3 = uvalue;
    m_uDcAlarm3 = uvalue;

    m_uDcWord4 = uvalue;
    m_uDcState4 = uvalue;
    m_uDcFault4 = uvalue;
    m_uDcAlarm4 = uvalue;

    m_uDcWord5 = uvalue;
    m_uDcState5 = uvalue;
    m_uDcFault5 = uvalue;
    m_uDcAlarm5 = uvalue;

    m_uDcWord6 = uvalue;
    m_uDcState6 = uvalue;
    m_uDcFault6 = uvalue;
    m_uDcAlarm6 = uvalue;

    for (int i = 0; i < ARRAYSIZE(m_uData); ++i)
    {
        m_uData[i] = uvalue;
    }

    //转发的100个FLOAT数据
    m_fTotalEnergy = fvalue;
    m_fHighVol = fvalue;
    m_fHighCur = fvalue;
    m_fHighActPower = fvalue;
    m_fInwindTemp = fvalue;
    m_fOutwindTemp = fvalue;

    m_fLowVol1 = fvalue;
    m_fLowCur1 = fvalue;
    m_fLowActPower1 = fvalue;

    m_fLowVol2 = fvalue;
    m_fLowCur2 = fvalue;
    m_fLowActPower2 = fvalue;

    m_fLowVol3 = fvalue;
    m_fLowCur3 = fvalue;
    m_fLowActPower3 = fvalue;

    m_fLowVol4 = fvalue;
    m_fLowCur4 = fvalue;
    m_fLowActPower4 = fvalue;

    m_fLowVol5 = fvalue;
    m_fLowCur5 = fvalue;
    m_fLowActPower5 = fvalue;

    m_fLowVol6 = fvalue;
    m_fLowCur6 = fvalue;
    m_fLowActPower6 = fvalue;

    for (int i = 0; i < ARRAYSIZE(m_fData); ++i)
    {
        m_fData[i] = fvalue;
    }

    for (int i = 0; i < ARRAYSIZE(m_uSetData); ++i)
    {
        m_uSetData[i] = uvalue;
    }

    for (int i = 0; i < ARRAYSIZE(m_uSetDataCopy); ++i)
    {
        m_uSetDataCopy[i] = uvalue;
    }
}
